
/**
 * @Author: XJH
 * @Description: TODO
 * @Date: 2025/10/25 21:09
 * @Version: 1.0
 */
/**
 * 你的NumArray对象将被实例化并像这样调用
 * NumArray obj = new NumArray(nums);
 * int param_1 = obj.sumRange(left,right);
 */
class NumArray {
    private final int[] s;

    public NumArray(int[] nums) {
        s=new int[nums.length+1];
        for(int i=0;i<nums.length;i++){
            s[i+1]=s[i]+nums[i];
        }
    }

    public int sumRange(int left, int right) {
      return s[right+1]-s[left];
    }
    public static void main(String[] args) {
        //输入：
        //["NumArray", "sumRange", "sumRange", "sumRange"]
        //[[[-2, 0, 3, -5, 2, -1]], [0, 2], [2, 5], [0, 5]]
        int[] nums = {-2, 0, 3, -5, 2, -1};
        NumArray obj = new NumArray(nums);
        System.out.println(obj.sumRange(0, 2));

    }
}
